﻿namespace Codeblack.TfsScrumboard.UI.Pages
{
    using System;
    using System.Web.UI;
    using Codeblack.TfsScrumboard.Interfaces;
    using Codeblack.TfsScrumboard.Resources;
    using Codeblack.TfsScrumboard.Runtime;
    using Codeblack.TfsScrumboard.UI.Controls;
    using Microsoft.Practices.Unity;
    using Microsoft.TeamFoundation.WebAccess.Controls;
    using Microsoft.TeamFoundation.WebAccess.UI;

    /// <summary>
    /// Base-class for all Scrumboard pages.
    /// </summary>
    public class ScrumboardPage : WebAccessPage
    {
        #region Constructor

        public ScrumboardPage()
        {
            Container.Instance.BuildUp(this.GetType(), this, null);
        }

        #endregion

        #region Properties

        public string BacklogName { get; set; }

        #endregion

        #region Dependency properties

        [Dependency]
        public IScrumboardService ScrumboardService { get; set; }

        #endregion

        #region Page overrides

        /// <summary>
        /// Handles the System.Web.UI.Control.Load event.
        /// </summary>
        /// <param name="e">The System.EventArgs object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.BacklogName = this.Request.QueryString["backlog"];
            if (this.BacklogName == null)
            {
                this.BacklogName = string.Empty;
            }
        }

        /// <summary>
        /// Handles the System.Web.UI.Control.PreRender event.
        /// </summary>
        /// <param name="e">An System.EventArgs that contains the event data.</param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            ScriptHelper.RegisterLocalScriptIncludeCommon(this, "~/Resources/Scripts/jquery-1.7.1.min.js");
            ScriptHelper.RegisterLocalScriptIncludeCommon(this, "~/Resources/Scripts/jquery-ui-1.8.13.custom.min.js");
            ScriptHelper.RegisterLocalScriptIncludeCommon(this, "~/Resources/Scripts/jquery.blockui.js");
            ScriptHelper.RegisterLocalScriptIncludeCommon(this, "~/Resources/Scripts/jsrender.js");

            // register the script needed by the backlogs
            ScriptHelper.RegisterLocalScriptIncludeCommon(this, "~/Resources/Scripts/Scrumboard.js");
            ScriptHelper.RegisterObjectScript(this, "scrumboard", new object[] { this.BacklogName, base.Locator });
        }

        #endregion
    }
}
